package com.elive.service.impl;

import com.elive.common.ServerResponse;
import com.elive.dao.DeviceMapper;
import com.elive.pojo.Device;
import com.elive.service.IDeviceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by wuyin on 2018/3/12.
 */
@Service("iDeviceService")
public class DeviceServiceImpl implements IDeviceService {

    @Autowired
    private DeviceMapper deviceMapper;

    @Override
    public ServerResponse<PageInfo> getDeviceList(int pageNum, int pageSize) {
        //startPage
        PageHelper.startPage(pageNum,pageSize);
        //填充自己的SQL查询逻辑
        List<Device> deviceList = deviceMapper.selectDeviceList();
        if(deviceList.size() != 0){
            PageInfo pageResult = new PageInfo(deviceList);
            return ServerResponse.createBySuccess(pageResult);
        }else {
            return ServerResponse.createByErrorMessage("没有设备记录");
        }
    }
}
